package com.videri.match.client;

import java.util.*;
import java.io.Serializable;
import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * This class stores in a generic format the information necessary
 * for storing a category of matchings.  This class attempts to store all 
 * the matchings associated with a given category.
 * 
 * @author Michael Bauer
 *
 */
public class Category implements IsSerializable, Serializable{
	
	private static final long serialVersionUID = -337549481484415750L;
	private String myCategoryName;
	/**
	 * @gwt.typeArgs <com.videri.match.client.Matching>
	 */
	private HashSet myMatchings;
	
	/**
	 * This will create a new Category
	 */
	public Category(){
		myCategoryName = new String();
		myMatchings = new HashSet();
	}
	
	/**
	 * This will create a new Category with the specified name
	 * @param name The name of the category
	 */
	public Category(String name){
		myCategoryName=name;
		myMatchings = new HashSet();
	}
	
	/**
	 * This will return the name of the category
	 * @return The name of the category in the form of a string
	 */
	public String getCategoryName(){
		return myCategoryName;
	}
	
	// This method should only ever be called by the Servlet
	/**
	 * This will add the specified Matching to the Category
	 * @param match The Matching to be added to the Category
	 */
	public void addMatching(Matching match){
		myMatchings.add(match);
	}
	
	// This should only ever be called by the Servlet
	/**
	 * This will return a set of the names associated with
	 * all the Matchings in this Category.
	 * @return Set containing the names of all Matchings in the Category
	 */
	public Set getMatchingNames(){
		HashSet names = new HashSet();
		Iterator it = myMatchings.iterator();
		while(it.hasNext())
			names.add(((Matching)(it.next())).getName());
		return names;
	}
}
